﻿using System.Linq;
using System.Web.Mvc;
using CMSMVC4.Filters;

namespace CMSMVC4.Areas.Admin.Controllers
{
    // Camnv
    [Authorize(Roles = "Admin,Feedback")]
    public class FeedbackController : Controller
    {
        CMSMVC4Entities _db = new CMSMVC4Entities();
        //
        // GET: /Admin/Feedback/List
        #region
        public ActionResult ListFeedback()
        {
            ViewBag.M = new CommandSql().GetParrentByMenu("/Admin/Feedback/ListFeedback").Rows[0]["Parrent"];
            var data = new CommandSql().GetAllFeedback();
            return View(data);
        }
        #endregion

        //
        // GET: /Admin/Feedback/EditFeedback
        #region
        [HttpGet]
        public ActionResult ViewFeedback(int id)
        {
            ViewBag.Data = new CommandSql().GetFeedbackById(id).Rows[0];
            return View();
        }
        #endregion

        //
        // GET: /Admin/Feedback/Delete
        #region
        [HttpGet]
        public ActionResult Delete(int id)
        {
            return PartialView();
        }

        [HttpPost]
        public JsonResult Delete(string[] id)
        {
            if (id != null)
            {
                foreach (var i in id)
                {
                    int idcomment;
                    int.TryParse(i, out idcomment);
                    var row = _db.Feedbacks.FirstOrDefault(x => x.Id == idcomment);
                    _db.Feedbacks.DeleteObject(row);
                    _db.SaveChanges();
                }
            }
            return Json(string.Empty, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}
